﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IClient
{
    class utils
    {
        public static readonly DateTime UnixTimeStampStart = new DateTime( 1970, 1, 1, 0, 0, 0, DateTimeKind.Utc );

        public static DateTime Ticks2DateTime( long value )
        {
            DateTime time =
                TimeZoneInfo.ConvertTimeFromUtc( new DateTime( value ),
                TimeZoneInfo.Local );
            return time;
        }

        public static long DateTime2Ticks( DateTime time )
        {
            long value = time.ToUniversalTime( ).Ticks;
            return value;
        }

        public static long DateTime2TimeStamp( DateTime dateTime )
        {
            return (long)( dateTime.ToUniversalTime( ) - UnixTimeStampStart ).TotalSeconds;
        }

        public static DateTime TimeStamp2DateTime( long sec )
        {
            return UnixTimeStampStart.AddSeconds( sec ).ToLocalTime( );
        }

    }
}
